<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
</head>
<body>
    <div id="app">
        {{msg}}
       <foo ref="ff"></foo>
    </div>    

    <template id="t1">
        <div>
            Vue 子组件
        </div>
    </template>

    <script>
        /*

            子组件访问父组件的属性: 通过子组件的props
            子组件访问父组件的方法: 通过子组件的$emit

            父组件访问子组件的属性：$refs
            父组件访问子组件的方法：$refs


        */
        var app = new Vue({
            el: "#app",
            data : {
                msg: "父组件msg"
            },
            mounted() {
                this.f1();
            },
            methods: {
                f1() {
                    // console.log(this.$refs.ff.msg);
                    this.msg = this.$refs.ff.msg;

                    this.$refs.ff.f1();
                }
            },
            components: {
                "foo": {
                    template: "#t1",
                    data() {
                        return {
                            msg: "子组件msg"
                        }
                    },
                    methods: {
                        f1() {
                            console.log("子组件f1");
                            
                        }
                    }
                }
            }
        });
    </script>
</body>
</html>